{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <div class="layui-card-header">
            <i class="fa fa-pencil"></i> 编辑会员
        </div>
        <form class="layui-form" action="">
            <input type="hidden" name="admin_id" value="{$info.admin_id}" />
            <div class="layui-form-item">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="user_name" value="{$info.user_name}" placeholder="请输入用户名" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">手机号</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="mobile" value="{$info.mobile}" placeholder="手机号" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">登陆密码</label>
                <div class="layui-input-inline layui-input-wrap">
                    <input type="text" name="password" value="{$info.password}" placeholder="登陆密码" autocomplete="off" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">所属角色</label>
                <div class="layui-input-inline layui-input-wrap">
                    <select name="role_id" lay-verify="required">
                        {foreach $all_role as $role}
                            <option value="{$role['role_id']}">{$role['role_name']}</option>
                        {/foreach}
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
                </div>
            </div>
        </form>
    </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });

        // 指定开关事件
        // form.on('switch(switchTest)', function(data){
        //     layer.msg('开关 checked：'+ (this.checked ? 'true' : 'false'), {
        //         offset: '6px'
        //     });
        //     layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是 ON|OFF', data.othis)
        // });

        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('save')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.tableIns.reload()
                    },1000)
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });


    });
</script>
</body>
</html>